package com.qf.controller;

import com.qf.pojo.Druginfo;
import com.qf.pojo.PageUtils;
import com.qf.service.DruginfoService;
import com.qf.utils.UploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/druginfo")
public class DruginfoController {
    @Autowired
    DruginfoService druginfoService;
    @RequestMapping("/findAll/{page}/{size}")
    public PageUtils findAll(@PathVariable("page")Integer page, @PathVariable("size")Integer size){

        return druginfoService.findAll(page,size);
    }

    @RequestMapping("/findById")
    public Druginfo findById(String id){
        return druginfoService.findById(id);
    }

    @RequestMapping("/saveAndUpdate")
    public String saveAndUpdare(@RequestBody Druginfo druginfo){
        druginfoService.insertAndUpdate(druginfo);
        return "success";
    }

    @RequestMapping("/delete")
    public String delete(@RequestBody Map map){
        String drugId = (String) map.get("drugId");
        druginfoService.delete(drugId);
        return "success";
    }
    /*上传*/
    @RequestMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile multipartFile){
        UploadUtils uploadUtils = new UploadUtils();
        String upload = uploadUtils.upload(multipartFile);
        return upload;
    }



}
